<template>
  <div class="edit-all">
    <!--弹窗-->
    <el-dialog  v-dialogDrag   :title="'批量修改'" :visible.sync="dialogFormVisible" width="66%" @close="dialogClose" @opened="dialogOpened">
      <el-form ref="dialogForm" :inline="true" :model="form" :rules="rules" label-width="66px">
        <el-form-item label="工资项" prop="salaryId">
          <el-select v-model="form.salaryId" style="width:50%;" placeholder="--请选择--" @change="selectColumnName">
            <template v-for="item in getSalaryNames">
              <el-option :key="item.value" :label="item.key" :value="item.value" />
            </template>
          </el-select>
        </el-form-item>
        <el-form-item label="公式" prop="inputFormula">
          <el-input
                id="formulaTextarea"
                v-model="form.inputFormula"
                type="textarea"
                :rows="3"
                style="width:400px;"
                
                oncontextmenu="return false;"
                ondragstart="return false;"
              />
          <!-- <el-input id="formulaTextarea" v-model="form.inputFormula" type="textarea" :rows="3" style="width: 400px;" readonly /> -->
        </el-form-item>
      </el-form>
      <el-row style="margin-top: 20px">
        <el-col v-if="ifShowSalary" :span="8">
          <!--查询所有工资项（包括计算项）-->
          <div
            class="salary-select"
            style="height:300px;"
          >
            <el-button
              v-for="(item, index) in salaryList"
              :key="item.salaryCode"
              class="salary-option"
              @click="selectSalary(index)"
            >{{ item.salaryName }}
            </el-button>
          </div>
        </el-col>
        <el-col v-if="ifShowSalary" :span="8">
          <div class="keyboard">
            <!--虚拟键盘-->
            <el-row
              v-for="(list, index) in keyList"
              :key="index"
            >
              <el-col
                v-for="(item, indexInner) in list"
                :key="indexInner"
                :span="8"
              >
                <el-button
                  class="key-button"
                  @click="keydown(item)"
                >{{
                  item
                }}</el-button>
              </el-col>
            </el-row>
          </div>
        </el-col>
        <el-col :span="8">
          <el-button @click="newTable">生成</el-button>
          <el-button @click="reset">重置</el-button>
        </el-col>
      </el-row>
      <vxe-table v-if="ifShowTable" border="inner" :data="tmp_table_list" fit class="my-test" :header-cell-style="{background:'#eef1f6',color:'#606266'}" :height="tableHeight">
        <vxe-table-column title="工资月份">
          <template slot-scope="{row}">
            <span>{{ row.currentMonth }}</span>
          </template>
        </vxe-table-column>
        <vxe-table-column title="科室">
          <template slot-scope="{row}">
            <span>{{ row.deptId | deptNameFilter(that) }}</span>
          </template>
        </vxe-table-column>
        <vxe-table-column title="身份证号">
          <template slot-scope="{row}">
            <span>{{ row.idenNo  }}</span>
          </template>
        </vxe-table-column>
        <vxe-table-column title="姓名">
          <template slot-scope="{ row }">
            <span>{{ row.personName }}</span>
          </template>
        </vxe-table-column>
        <vxe-table-column v-for="item in columnNames" v-if="item.split('_')[0] === form.salaryId" :key="item" :title="item.split('_')[0] | salaryNameFilter(that)">
          <template slot-scope="{ row }">
            <span>{{ Number(row[item.split('_')[0]]).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,") }}</span>
          </template>
        </vxe-table-column>
      </vxe-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="handleSave">保存</el-button>
        <el-button @click="dialogClose">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { queryUnitSalaryReportPage } from '@/api/unitSalaryReport/unitSalaryReport'
import { getAllSalary } from '@/api/salaryConfigManage/formulaManage'
import { submitData } from '@/api/unitSalaryReport/unitSalaryReport'
import { deepClone } from '@/utils'
import Pagination from '@/components/Pagination'
import tableEmpty from '@/components/table/empty'
import AgencyTree from '@/components/tree/agencyTree'
import Drag from '@/components/Drag'
import { confirmSalary } from '@/api/salaryReport/financialVerify'


const chReg = /^[\u4e00-\u9fa5]$/
const reg1 = /^\s$/
const reg2 = /^\[$/
const reg3 = /^]$/
const reg4 = /^\($/
const reg5 = /^\)$/

export default {
  name: 'UnitSalaryReportChildrenEditAll',
  components: { Pagination, tableEmpty, AgencyTree, Drag },
  filters: {
    deptNameFilter(value, that) {
      for (const item of that.deptNames) {
        if (value === item.code) {
          return item.name
        }
      }
    },
    //号码脱敏显示
    hideMiddle(val) {
      if(val!== undefined&& val!== null){//避免列表中存在空数据报错
        return `${val.substring(0,4)}****${val.substring(val.length-4)}`
      }else{
        return val
      }
    },
    // 工资项滤器
    salaryNameFilter(value, that) {
      for (const item of that.salaryNames) {
        if (item.value === value) {
          return item.key
        }
      }
    }
  },
  props: {
    selectData: { // 选择项
      type: Array
    },
    columnNames: {
      type: Array
    },
    deptNames: {
      type: Array
    },
    salaryNames: {
      type: Array
    },
    computeFormula: {
      type: Array
    }
  },
  data() {
    const evil = fn => {
      // 一个变量指向Function，防止有些前端编译工具报错
      const Fn = Function
      return new Fn('return ' + fn)()
    }
    // 公式可行性校验
    const formulaExecuteVerify = (rule, value, callback) => {
      const formula = value.replace(/\s\[.+?]\s/g, ' 1 ')
      try {
        evil(formula)
        callback()
      } catch (err) {
        callback(new Error('该公式不可被执行'))
      }
    }
    return {
      ifShowSalary: false, // 是否显示公式
      ifShowTable: false, // 是否显示列表
      table_list: [],
      tmp_table_list: [], // 备份
      formInline: {
        user: '',
        region: ''
      },
      that: this,
      dialogFormVisible: true,
      total: 0,
      form: {
        inputFormula: '',
        formula: '',
        salaryId: ''
      },
      salaryList: [],
      salaryNameMap: {}, // 工资名称对应工资id
      salaryIdMap: {}, // 工资id对应工资名称
      keyList: [
        ['+', '-', '*'],
        ['/', '(', ')'],
        ['7', '8', '9'],
        ['4', '5', '6'],
        ['1', '2', '3'],
        ['', '0', '.']
      ],
      tableHeight: null,
      rules: {
        salaryId: [
          { required: true, message: '请选择工资项', trigger: 'change' }
        ],
        inputFormula: [
          { required: true, message: '请输入公式', trigger: 'blur' },
          { validator: formulaExecuteVerify, trigger: 'change' }
        ]
      }
    }
  },
  computed: {
    getSalaryNames() {
      return this.salaryNames.filter(item => {
        return item.iscompute !== 1
      })
    }
  },
  watch: {},
  created() {},
  mounted() {
    this.table_list = this.selectData
    this.tmp_table_list = deepClone([...this.selectData]) // 做备份
    this.getAllSalary()
    this.getTbHeight()
  },
  beforeMount() {},
  methods: {
    getList() {
      queryUnitSalaryReportPage(this.listQuery)
        .then(response => {
          response.data.rows.splice(0, 1)
          response.data.rows.splice(response.data.rows.length - 1, 1)
          this.table_list = response.data.rows
          this.tmp_table_list = deepClone([...this.table_list]) // 做备份
        })
        .catch(() => {
          this.table_list = []
          this.tmp_table_list = deepClone([...this.table_list]) // 做备份
        })
    },
    selectColumnName() {
      this.tmp_table_list = deepClone([...this.table_list]) // 做备份
      this.form.inputFormula = '' // 清空规则
      this.ifShowSalary = true
    },
    getTbHeight() {
      this.tableHeight = window.innerHeight - 400
    },
    newTable() {
      
      this.$refs.dialogForm.validate(valid => {
        
        if (valid) {
          
          this.tmp_table_list = deepClone([...this.table_list]) // 做备份
          const argList = []
          const formula = this.form.inputFormula
          const args = formula.split(' ')
          for (let arg of args) {
            if (arg.startsWith('[') && arg.endsWith(']')) {
              arg = arg.substring(1, arg.length - 1)
              const salaryId = this.salaryNameMap[arg]
              argList.push('&' + salaryId + '&')
            } else {
              arg = arg.replace(/([\+\-\*\/\(\)%])/g, ' $1 ')
              const symbols = arg.split(' ')
              for (const symbol of symbols) {
                if (symbol !== '') {
                  argList.push(symbol)
                }
              }
            }
          }
          this.form.formula = argList.join(',')
          // 列表对应的根据公式修改结果
         
          for (const row of this.tmp_table_list) {
            const answer = this.form.salaryId
            const args = this.form.formula.split(',')
            let calc = ''
            for (let arg of args) {
              if (arg.startsWith('&') && arg.endsWith('&')) {
                arg = arg.substring(1, arg.length - 1)
                if (arg !== 'null') {
                  calc += row[arg] === '' ? '0' : row[arg]
                } else {
                  calc += 0
                }
              } else {
                calc += arg
              }
            }
            row[answer] = Number(this.$math.round(this.$math.evaluate(calc), 2))
          }

          
           this.calculate(this.tmp_table_list)
           
          this.ifShowSalary = false
          this.ifShowTable = true
        }
      })
    },
    calculate(submitList) {
      // 获取每一行的数据进行计算
      for (const submit of submitList) {
        for (const computeFormula of this.computeFormula) {
          const meritPayCode = computeFormula.meritPayCode.split(',')
          if (meritPayCode.includes(submit.meritPayCode)) {
            const formula = computeFormula.computeFormula
            const decimalPlace = computeFormula.decimalPlace
            const equation = formula.split('=')
            const answer = equation[0]
            const args = equation[1].split(',')
            
            let calc = ''
            for (let arg of args) {
              if (arg.startsWith('&') && arg.endsWith('&')) {
                arg = arg.substring(1, arg.length - 1)
                if (arg !== 'null') {
                  calc += submit[arg] === ''||submit[arg] ===undefined ? '0' : submit[arg]
                } else {
                  calc += 0
                }
              } else {
                calc += arg
              }
            }
            submit[answer] = Number(this.$math.round(this.$math.evaluate(calc), decimalPlace))
          }
        }
      }
    },
    handleSave() {
      this.tmp_table_list.forEach(item => {
        //item.columnNames = this.form.salaryId
        item.columnNames = this.getSubmitcolumnNames()
      })
      submitData(this.tmp_table_list).then(() => {
        this.$emit('close', 2)
      })
    },
    getSubmitcolumnNames() {
      let columnNames=''
      this.salaryNames.forEach(function(item){
        if(item.iscompute === 1){
          columnNames+=item.value+','
        }
      })
      return columnNames+this.form.salaryId
    },
    reset() {
      this.ifShowSalary = true
      this.ifShowTable = false
      this.tmp_table_list = deepClone([...this.table_list]) // 做备份
      this.form.inputFormula = '' // 清空规则
    },
    dialogClose() {
      this.$emit('close', 1)
    },
    getAllSalary() {
      // 获取所有工资项
      getAllSalary().then(res => {
        this.salaryList = res.data
        for (const salary of this.salaryList) {
          this.salaryNameMap[salary.salaryName] = salary.salaryCode
          this.salaryIdMap[salary.salaryCode] = salary.salaryName
        }
      })
    },
    /**
     *自定义键盘退格键删除
     */
    dialogOpened() {
      const formulaTextarea = document.getElementById('formulaTextarea')
      formulaTextarea.onkeydown = event => {
        // 自定义回退键删除事件
        if (event.code === 'Backspace') {
          let startPos = formulaTextarea.selectionStart
          const endPos = formulaTextarea.selectionEnd
          if (startPos === undefined || endPos === undefined) return
          const txt = formulaTextarea.value
          let result = ''
          if (startPos !== endPos) {
            let str1 = ''
            let str2 = ''
            const fontStr = txt.substring(0, startPos)
            const backStr = txt.substring(endPos)
            // 被删除字符串的第一个字符
            const startChar = txt.substring(startPos, startPos + 1)
            // 被删除字符串的最后一个字符
            const endChar = txt.substring(endPos - 1, endPos)
            // 判断第一个字符
            if (
              chReg.test(startChar) ||
              reg2.test(startChar) ||
              reg3.test(startChar)
            ) {
              str1 = fontStr.substring(0, fontStr.lastIndexOf(' '))
            } else if (reg1.test(startChar)) {
              // 如果是空格的话，需要判断光标前的字符是否是】或【
              const char = txt.substring(startPos - 1, startPos)
              if (reg3.test(char) || reg2.test(char)) {
                str1 = fontStr.substring(0, fontStr.lastIndexOf(' '))
              } else {
                str1 = txt.substring(0, startPos)
              }
            } else if (reg4.test(startChar) || reg5.test(startChar)) {
              // 如果是小括号的话，需要判断光标前或后的字符是否是汉字
              const char1 = txt.substring(startPos - 1, startPos)
              const char2 = txt.substring(startPos + 1, startPos + 2)
              if (chReg.test(char1) || chReg.test(char2)) {
                str1 = fontStr.substring(0, fontStr.lastIndexOf(' '))
              } else {
                str1 = txt.substring(0, startPos)
              }
            } else {
              str1 = txt.substring(0, startPos)
            } // 判断最后一个字符
            if (
              chReg.test(endChar) ||
              reg2.test(endChar) ||
              reg3.test(endChar)
            ) {
              str2 = backStr.substring(backStr.indexOf(' ') + 1)
            } else if (reg1.test(endChar)) {
              const char = txt.substring(endPos, endPos + 1)
              // 如果是空格的话，需要判断光标后的字符是否是【或】
              if (reg3.test(char) || reg2.test(char)) {
                str2 = backStr.substring(backStr.indexOf(' ') + 1)
              } else {
                str2 = txt.substring(endPos)
              }
            } else if (reg4.test(endChar) || reg5.test(endChar)) {
              // 如果是小括号的话，需要判断光标前或后的字符是否是汉字
              const char1 = txt.substring(endPos - 1, endPos)
              const char2 = txt.substring(endPos, endPos + 1)
              if (chReg.test(char1) || chReg.test(char2)) {
                str2 = backStr.substring(backStr.indexOf(' ') + 1)
              } else {
                str2 = txt.substring(endPos)
              }
            } else {
              str2 = txt.substring(endPos)
            }
            result = str1 + str2
            startPos = str1.length
          } else {
            const fontStr = txt.substring(0, startPos - 1)
            const backStr = txt.substring(startPos)
            // 被删除的字符
            const delChar = txt.substring(startPos - 1, startPos)
            // 判断字符
            if (
              chReg.test(delChar) ||
              reg2.test(delChar) ||
              reg3.test(delChar)
            ) {
              result =
                fontStr.substring(0, fontStr.lastIndexOf(' ')) +
                backStr.substring(backStr.indexOf(' ') + 1)
              startPos = fontStr.lastIndexOf(' ')
            } else if (reg1.test(delChar)) {
              const char = txt.substring(startPos - 2, startPos - 1)
              if (reg3.test(char)) {
                // 工资项尾部空格
                result =
                  fontStr.substring(0, fontStr.lastIndexOf(' ')) + backStr
                startPos = fontStr.lastIndexOf(' ')
              } else {
                // 工资项首部空格
                result = fontStr + backStr.substring(backStr.indexOf(' ') + 1)
                startPos = fontStr.length
              }
            } else if (reg4.test(delChar) || reg5.test(delChar)) {
              const char1 = txt.substring(startPos - 1, startPos)
              const char2 = txt.substring(startPos + 1, startPos + 2)
              if (chReg.test(char1) || chReg.test(char2)) {
                result =
                  fontStr.substring(0, fontStr.lastIndexOf(' ')) +
                  backStr.substring(backStr.indexOf(' ') + 1)
                startPos = fontStr.lastIndexOf(' ')
              } else {
                result = fontStr + backStr
                startPos = fontStr.length
              }
            } else {
              result = fontStr + backStr
              startPos = fontStr.length
            }
          }
          formulaTextarea.value = result
          this.form.inputFormula = result
          // 重新定义光标位置
          formulaTextarea.focus()
          formulaTextarea.selectionStart = startPos
          formulaTextarea.selectionEnd = startPos
        }
        return false
      }
    },
    /**
     *点击虚拟键盘
     */
    keydown(key) {
      const formulaTextarea = document.getElementById('formulaTextarea')
      let startPos = formulaTextarea.selectionStart
      const endPos = formulaTextarea.selectionEnd
      if (startPos === undefined || endPos === undefined) return
      const txt = formulaTextarea.value
      let result = ''
      if (startPos !== endPos) {
        let str1 = ''
        let str2 = ''
        const fontStr = txt.substring(0, startPos)
        const backStr = txt.substring(endPos)
        // 被选中字符串的第一个字符
        const startChar = txt.substring(startPos, startPos + 1)
        // 被选中字符串的最后一个字符
        const endChar = txt.substring(endPos - 1, endPos)
        // 判断第一个字符
        if (
          chReg.test(startChar) ||
          reg2.test(startChar) ||
          reg3.test(startChar)
        ) {
          str1 = fontStr.substring(0, fontStr.lastIndexOf(' '))
        } else if (reg1.test(startChar)) {
          // 如果是空格的话，需要判断光标前的字符是否是】或【
          const char = txt.substring(startPos - 1, startPos)
          if (reg3.test(char) || reg2.test(char)) {
            str1 = fontStr.substring(0, fontStr.lastIndexOf(' '))
          } else {
            str1 = txt.substring(0, startPos)
          }
        } else if (reg4.test(startChar) || reg5.test(startChar)) {
          // 如果是小括号的话，需要判断光标前或后的字符是否是汉字
          const char1 = txt.substring(startPos - 1, startPos)
          const char2 = txt.substring(startPos + 1, startPos + 2)
          if (chReg.test(char1) || chReg.test(char2)) {
            str1 = fontStr.substring(0, fontStr.lastIndexOf(' '))
          } else {
            str1 = txt.substring(0, startPos)
          }
        } else {
          str1 = txt.substring(0, startPos)
        } // 判断最后一个字符
        if (chReg.test(endChar) || reg2.test(endChar) || reg3.test(endChar)) {
          str2 = backStr.substring(backStr.indexOf(' ') + 1)
        } else if (reg1.test(endChar)) {
          const char = txt.substring(endPos, endPos + 1)
          // 如果是空格的话，需要判断光标后的字符是否是【或】
          if (reg3.test(char) || reg2.test(char)) {
            str2 = backStr.substring(backStr.indexOf(' ') + 1)
          } else {
            str2 = txt.substring(endPos)
          }
        } else if (reg4.test(endChar) || reg5.test(endChar)) {
          // 如果是小括号的话，需要判断光标前或后的字符是否是汉字
          const char1 = txt.substring(endPos - 1, endPos)
          const char2 = txt.substring(endPos, endPos + 1)
          if (chReg.test(char1) || chReg.test(char2)) {
            str2 = backStr.substring(backStr.indexOf(' ') + 1)
          } else {
            str2 = txt.substring(endPos)
          }
        } else {
          str2 = txt.substring(endPos)
        }
        result = str1 + key + str2
        startPos = str1.length + key.length
      } else {
        const fontStr = txt.substring(0, startPos)
        const backStr = txt.substring(startPos)
        // 获取光标前后字符
        const startChar = txt.substring(startPos - 1, startPos)
        const endChar = txt.substring(startPos, startPos + 1)
        // 前后都是汉字
        if (
          (chReg.test(startChar) && chReg.test(endChar)) ||
          // 前是汉字，后是中括号】
          (chReg.test(startChar) && reg3.test(endChar)) ||
          // 前是中括号【，后是汉字
          (reg2.test(startChar) && chReg.test(endChar)) ||
          // 前是空格，后是中括号【
          (reg1.test(startChar) && reg2.test(endChar)) ||
          // 前是中括号】，后是空格
          (reg3.test(startChar) && reg1.test(endChar)) ||
          // 前是汉字或【，后是小括号（
          ((chReg.test(startChar) || reg2.test(startChar)) &&
            reg4.test(endChar)) ||
          // 前是小括号（，后是汉字或】
          (reg4.test(startChar) &&
            (chReg.test(endChar) || reg3.test(endChar))) ||
          // 前是汉字或【，后是小括号）
          ((chReg.test(startChar) || reg2.test(startChar)) &&
            reg5.test(endChar)) ||
          // 前是小括号），后是汉字或】
          (reg5.test(startChar) && (chReg.test(endChar) || reg3.test(endChar)))
        ) {
          result =
            fontStr.substring(0, fontStr.lastIndexOf(' ')) +
            key +
            backStr.substring(backStr.indexOf(' ') + 1)
          startPos = fontStr.lastIndexOf(' ') + key.length
        } else {
          result = fontStr + key + backStr
          startPos = fontStr.length + key.length
        }
      }
      formulaTextarea.value = result
      this.form.inputFormula = result
      // 赋值给表单中的的字段//重新定义光标位置
      formulaTextarea.focus()
      formulaTextarea.selectionStart = startPos
      formulaTextarea.selectionEnd = startPos
    },
    /**
     *点选工资项
     */
    selectSalary(index) {
      const salaryName = ' [' + this.salaryList[index].salaryName + '] '
      const formulaTextarea = document.getElementById('formulaTextarea')
      let startPos = formulaTextarea.selectionStart
      const endPos = formulaTextarea.selectionEnd
      if (startPos === undefined || endPos === undefined) return
      const txt = formulaTextarea.value
      let result = ''
      if (startPos !== endPos) {
        let str1 = ''
        let str2 = ''
        const fontStr = txt.substring(0, startPos)
        const backStr = txt.substring(endPos)
        // 被选中字符串的第一个字符
        const startChar = txt.substring(startPos, startPos + 1)
        // 被选中字符串的最后一个字符
        const endChar = txt.substring(endPos - 1, endPos)
        // 判断第一个字符
        if (
          chReg.test(startChar) ||
          reg2.test(startChar) ||
          reg3.test(startChar)
        ) {
          str1 = fontStr.substring(0, fontStr.lastIndexOf(' '))
        } else if (reg1.test(startChar)) {
          // 如果是空格的话，需要判断光标前的字符是否是】或【
          const char = txt.substring(startPos - 1, startPos)
          if (reg3.test(char) || reg2.test(char)) {
            str1 = fontStr.substring(0, fontStr.lastIndexOf(' '))
          } else {
            str1 = txt.substring(0, startPos)
          }
        } else if (reg4.test(startChar) || reg5.test(startChar)) {
          // 如果是小括号的话，需要判断光标前或后的字符是否是汉字
          const char1 = txt.substring(startPos - 1, startPos)
          const char2 = txt.substring(startPos + 1, startPos + 2)
          if (chReg.test(char1) || chReg.test(char2)) {
            str1 = fontStr.substring(0, fontStr.lastIndexOf(' '))
          } else {
            str1 = txt.substring(0, startPos)
          }
        } else {
          str1 = txt.substring(0, startPos)
        } // 判断最后一个字符
        if (chReg.test(endChar) || reg2.test(endChar) || reg3.test(endChar)) {
          str2 = backStr.substring(backStr.indexOf(' ') + 1)
        } else if (reg1.test(endChar)) {
          const char = txt.substring(endPos, endPos + 1)
          // 如果是空格的话，需要判断光标后的字符是否是【或】
          if (reg3.test(char) || reg2.test(char)) {
            str2 = backStr.substring(backStr.indexOf(' ') + 1)
          } else {
            str2 = txt.substring(endPos)
          }
        } else if (reg4.test(endChar) || reg5.test(endChar)) {
          // 如果是小括号的话，需要判断光标前或后的字符是否是汉字
          const char1 = txt.substring(endPos - 1, endPos)
          const char2 = txt.substring(endPos, endPos + 1)
          if (chReg.test(char1) || chReg.test(char2)) {
            str2 = backStr.substring(backStr.indexOf(' ') + 1)
          } else {
            str2 = txt.substring(endPos)
          }
        } else {
          str2 = txt.substring(endPos)
        }
        result = str1 + salaryName + str2
        startPos = str1.length + salaryName.length
      } else {
        const fontStr = txt.substring(0, startPos)
        const backStr = txt.substring(startPos)
        // 获取光标前后字符
        const startChar = txt.substring(startPos - 1, startPos)
        const endChar = txt.substring(startPos, startPos + 1)
        // 前后都是汉字
        if (
          (chReg.test(startChar) && chReg.test(endChar)) ||
          // 前是汉字，后是中括号】
          (chReg.test(startChar) && reg3.test(endChar)) ||
          // 前是中括号【，后是汉字
          (reg2.test(startChar) && chReg.test(endChar)) ||
          // 前是空格，后是中括号【
          (reg1.test(startChar) && reg2.test(endChar)) ||
          // 前是中括号】，后是空格
          (reg3.test(startChar) && reg1.test(endChar)) ||
          // 前是汉字或【，后是小括号（
          ((chReg.test(startChar) || reg2.test(startChar)) &&
            reg4.test(endChar)) ||
          // 前是小括号（后是汉字或】
          (reg4.test(startChar) &&
            (chReg.test(endChar) || reg3.test(endChar))) ||
          // 前是汉字或【，后是小括号）
          ((chReg.test(startChar) || reg2.test(startChar)) &&
            reg5.test(endChar)) ||
          // 前是小括号），后是汉字或】
          (reg5.test(startChar) && (chReg.test(endChar) || reg3.test(endChar)))
        ) {
          result =
            fontStr.substring(0, fontStr.lastIndexOf(' ')) +
            salaryName +
            backStr.substring(backStr.indexOf(' ') + 1)
          startPos = fontStr.lastIndexOf(' ') + salaryName.length
        } else {
          result = fontStr + salaryName + backStr
          startPos = fontStr.length + salaryName.length
        }
      }
      formulaTextarea.value = result
      this.form.inputFormula = result
      // 赋值给表单中的的字段 //重新定义光标位置
      formulaTextarea.focus()
      formulaTextarea.selectionStart = startPos
      formulaTextarea.selectionEnd = startPos
    }
  }
}
</script>

<style lang="scss" scoped>
@import "~@/styles/border.scss"; /*引入公共样式*/
.edit-all{}
.salary-select {
  height: 300px;
  overflow: scroll;
  overflow-x: hidden;

  .salary-option {
    height: 30px;
    width: 100%;
    margin-left: 0;
  }
}

.keyboard {
  height: 300px;
  padding: 0 32px;

  .el-col {
    text-align: center;
  }

  .key-button {
    height: 36px;
    width: 56px;
    margin: 6px;
  }
}

.app-title {
  margin-bottom: 15px;
  height: 20px;
  border-bottom: 1px solid #dcdfe6;
}

  .numCol {
    margin-top: 10px;
    span {
      font-size: 14px;
    }
  }

.drag-select {
  ::v-deep {
    .sortable-ghost {
      opacity: .8;
      color: #fff !important;
      background: #42b983 !important;
    }

    .el-tag {
      cursor: pointer;
    }
  }
}
::v-deep .el-select {
  .el-input {
    height: auto !important;
  }
}
</style>
